//
//  DetailsViewController.m
//  ShangChengMoBan
//
//  Created by 军 on 16/8/25.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "DetailsViewController.h"
#import "SDCycleScrollView.h"
@interface DetailsViewController ()<UIWebViewDelegate,UIAlertViewDelegate,SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *image;

@property (weak, nonatomic) IBOutlet UILabel *headerTitle;
@property (weak, nonatomic) IBOutlet UILabel *num;
@property (weak, nonatomic) IBOutlet SDCycleScrollView *sdcysle;

@end

@implementation DetailsViewController
{
    UIScrollView * scroll;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:@"积分兑换详情" WithColor:[UIColor colorWithHue:0.00 saturation:0.00 brightness:1.00 alpha:1.00]];
    [self drawBackButton];

    
    UIView * herderView = [[[NSBundle mainBundle]loadNibNamed:@"ImageHeader" owner:self options:nil] lastObject];
    herderView.frame = CGRectMake(0, 0, KScreenWidth, 227);
    _sdcysle.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    _sdcysle.imageURLStringsGroup = @[_firstMdoel.goods.goodsImg];
    _sdcysle.delegate = self;
    _sdcysle.autoScrollTimeInterval = 3;
    _sdcysle.dotColor = [UIColor whiteColor];
    _sdcysle.placeholderImage = [UIImage imageNamed:PLaceHolderImage];
    //[_image sd_setImageWithURL:[NSURL URLWithString:_firstMdoel.goods.goodsImg]];
    _headerTitle.text = _firstMdoel.goods.goodsName;
    _num.text = [NSString stringWithFormat:@"%@",_firstMdoel.exchangeIntegral];
   scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, KScreenWidth, KScreenHeight-70)];
    [scroll addSubview:herderView];
    scroll.backgroundColor=[UIColor colorWithHue:0.00 saturation:0.00 brightness:0.96 alpha:1.00];
    [self.view addSubview:scroll];
      UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, herderView.bottom+8, KScreenWidth, KScreenHeight-herderView.bottom-62)];
     webView.scrollView.scrollEnabled=NO;
    webView.delegate=self;
    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com/"]];
    [webView loadRequest:request];
    [scroll addSubview:webView];
       [self footView];
 }
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    CGFloat  height = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] floatValue];
    CGRect frame = webView.frame;
            frame.size.height = height;
            webView.frame = frame;
            scroll.contentSize = CGSizeMake(KScreenWidth, 215+height);
}
-(void)footView{
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, KScreenHeight-50, KScreenWidth, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    UIButton * footButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-20, 40)];
    [footButton setTitle:@"立即兑换" forState:UIControlStateNormal];
    footButton.backgroundColor = [UIColor colorWithHue:0.96 saturation:1.00 brightness:1.00 alpha:1.00];
    [footButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [footButton addTarget:self action:@selector(huiHuan) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:footButton];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:_firstMdoel.goodsId forKey:@"goodsId"];
    [dic setObject:_firstMdoel.exchangeIntegral forKey:@"exchangeIntegral"];
    [dic setObject:[self defaultLoadUserName] forKey:@"userName"];
    [NetWorking NEWjieKouQingQiu:JJSC_GoodsByPoints ANDIP:IP And:dic anBlock:^(NSDictionary *dic, NSError *error) {
        NSLog(@"%@",dic[Msg]);
        if (!error) {
            if ([dic[Code] intValue] == 200) {
                [[iToast makeText:@"  兑换成功!  "] show];
            }
        }
    }];
}

-(void)huiHuan{
     [TCUtils showAlertViewWithTitle:@"提醒" message:@"你确定要兑换这个宝贝吗?" delegate:self cancel:@"取消" other:@"确定" tag:100];
  
}
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
